<?php

/**
 * Copyright              [HD框架] (C)2011-2012 houdunwang ，Inc. 
 * Encoding               UTF-8 
 * @author                向军
 * Link                   http://www.houdunwang.com       
 * E-mail                 houdunwangxj@gmail.com
 */
class categoryControl extends rbacControl {
	//栏目列表
    function index() {
        $db = M("category");
        $category = $db->field("catid,cname,sort,pid")->all();
        $category = arr::channel($category,"catid","pid",0,2,"&nbsp;&nbsp;&nbsp;&nbsp;");
        $this->assign("category",$category);
        $this->display();
    }

    //添加栏目
    function add_show() {
        $this->display();
    }
    //添加栏目
    function add(){
        $db = M("category");
        if($db->add()){
            $this->success("添加栏目成功");
        }else{
            $this->error("添加栏目失败");
        }
    }
    function del(){
        $catid = $_GET['catid'];
        $db = M("category");
        $result  = $db->where("pid='$catid'")->find();
        if($result){
            $this->error("请先删除子目录");
        }else{
            if($db->del($catid)){
                $this->success("删除栏目成功");
            }else{
                $this->error("删除栏目失败，请重试");
            }
        }
    }
	function edit(){
	
		 $db = M("category");
        if($db->save()){
            $this->success("修改栏目成功");
        }else{
            $this->error("修改栏目失败");
        }
		
	}
	
	function edit_show(){
		$catid=$_GET['catid'];
	   $db = M("category");
        $category = $db->where("catid=$catid")->all();
		//p($category);
		foreach ($category as $v){
			$category=$v;
		}
		//p($category);
        $this->assign("category",$category);
        $this->display();
	
	}
	
	
	 //选择模板文件
    function selecttemplate() {
        C("debug",0);
        $path = C("tpl_index_dir") . '/' . C("tpl_style");
        $files = dir::tree($path, 'html');
		//p($path);p($files);
        $this->assign("tplpath", $path);
        $this->assign("files", $files);
        $this->display();
    }

}

?>
